import '../public/index'
import url from '../data/url'
import request from '../data/request'
import {tableConfig, header} from '../data/config'
import store from 'store'
import {getUrlParam} from '../data/util'

const base = url.base

let table
let storeData

let param = {
  title: 'buildId',
  content: getUrlParam('house')
}
/*** 获取housetype方法 ***/
let houseType = {
  data: {
    firstHeader: [],
    everyFloor: null, //楼层信息，房间信息，户型信息
    roofBin: [], //楼栋信息
    floors: 0,
    hbuId: null,
    editHouseInfo: null,
    activeHbuNum: null,
    pageNavData: {  //储存分页数据
      pageSize: 60,
      currentPage: 1,
      pageData: []
    },
    pageNavFn: null,
    editFloorData: [],
    storeDataFloors: null, //存放测试传给分页组件的数据
    tableBodyObj: {}  //存放渲染到页面表身的数据
  },
  init: () => {
    houseType.getData(param)
  },
  //重来新设计显示表格的方法
  getData: (res) => {
    let url = ''
    if (res.hbuId) {
      url = 'buildId=' + res.content + '&hbuId=' + res.hbuData
    } else {
      url = 'buildId=' + res.content
    }
    $.ajax({
      type: "GET",
      url: base + '/admin/house/facade.json?' + url,
      dataType: "json",
      headers: {
        myToken: Cookies.get('myToken')
      },
    }).then(res => {
      // console.log('hello', res)
      houseType.data.storeDataFloors = new Array(res.htList.length).fill([])
      houseType.data.activeHbuNum = res.hbuList
      houseType.data.hbuId = res.hbuId
      houseType.everyFloor(res)
      houseType.tableTitle(res.htList)
      houseType.getHowMany(res.hbuList)
      houseType.setHouseInfoHeader(res)
      houseType.getRoofBeam(res.hbuList)
    }).then(() => {
      console.log('获取数据完毕,开始渲染表单')
      houseType.setTableBodyData(houseType.data.everyFloor)
    })
  },
  //楼栋信息按钮
  getRoofBeam:
    (res) => {
      res.forEach(k => {
        $("#roof-beam .roof-list").append(houseType.renderRoofBeam(k))
      })
      Array.prototype.forEach.call(document.querySelectorAll("#roof-beam .roof-list button"), (k, index) => {
        if ($(k).attr('hb-id') == houseType.data.hbuId) {
          $(k).addClass('active-blue')
        }
      })
      houseType.bindRoofBeam()
    },
  //渲染楼栋信息
  renderRoofBeam:
    (data) => {
      if (!data.hbuUnitStr) {
        let str = `<button class="btn btn-default" type="submit" hb-id="${data.id}">${data.hbuNumStr}</button>`
        return str
      } else if (data.hbuUnitStr) {
        let str = `<button class="btn btn-default" type="submit" hb-id="${data.id}">${data.hbuNumStr}${data.hbuUnitStr}</button>`
        return str
      }
    },
  //绑定楼栋点击事件
  bindRoofBeam:
    () => {
      $("#roof-beam .roof-list button").on('click', (e) => {
        let str = $(e.target).attr('hb-id')
        param.hbuId = 'hbuId'
        param.hbuData = str
        //先清空之前的表格，再请求数据从新加载表格
        $("#table").children().remove()
        // $("#page-nav").remove()
        $('#roof-beam .roof-list').children().remove()
        // $('#house-info').children().remove()
        houseType.data.firstHeader = []
        houseType.getData(param)
      })
    },
  //添加页面顶部房屋信息
  setHouseInfoHeader:
    (res) => {
      console.log('res===>>>', res)
      $('#edit-buildName').text(res.hsList.buildName)
      $('#edit-hsBuildNum').text(res.hsList.hsBuildNum)
      $('#edit-hsSoldNum').text(res.hsList.hsSoldNum)
      $('#edit-remain').text(res.hsList.hsBuildNum - res.hsList.hsSoldNum)
    },
  //获取每层数据方法
  everyFloor:
    (res) => {
      let roofStore = res.htList
      roofStore.forEach(k => {
        k.everyFloor = []
        res.hList.forEach((n, index) => { //判断户型是否相同
          if (n.houseTypeId === k.idStr) {
            k.everyFloor.push(n)
          }
        })
        //设置最高楼层信息
        houseType.data.floors = res.hList[res.hList.length - 1].floor
      })
      houseType.data.everyFloor = roofStore
    },
//获取表头方法
  tableTitle:
    (res) => {
      // console.log('title:', res)
      res.forEach((k, index) => {
        houseType.data.firstHeader.push({
          info: index + 1 + '号（' + k.htStructure + '）' + k.typeName,
          setInArea: k.setInArea + '㎡',
          buildArea: k.buildArea + '㎡',
          houseTypeId: k.idStr
        })
      })
    },
  //渲染表头信息
  renderTableTitle:
    (data, index) => {
      // console.log('hello data', data)
      if (index === 0) {
        let str = `<tr class="mark-remove"><td rowspan="3"> </td><td colspan="4">${data.info}</td></tr>
                <tr class="mark-remove"><td colspan="2">建筑面积</td><td colspan="2">${data.buildArea}</td></tr>
                <tr class="mark-remove"><td colspan="2">套内面积</td><td colspan="2">${data.setInArea}</td></tr>`
        return str
      } else {
        let str = `<tr class="mark-remove"><td colspan="4">${data.info}</td></tr>
                <tr class="mark-remove"><td colspan="2">建筑面积</td><td colspan="2">${data.buildArea}</td></tr>
                <tr class="mark-remove"><td colspan="2">套内面积</td><td colspan="2">${data.setInArea}</td></tr>`
        return str
      }
    },
  //渲染房间信息
  renderTableBody:
    (data, index) => {
      let status = ''
      let staClass = ''
      let canEdit = true
      switch (data.status) {
        // case 0:
        //   status = '待售'
        //   staClass = 'sta-red'
        //   break
        // case 1:
        // case 2:
        //   status = '在售'
        //   staClass = 'sta-green'
        //   break
        // case 3:
        //   status = '已售'
        //   staClass = 'sta-blue'
        //   break
        case 0:
          status = '待售'
          staClass = 'sta-red'
          break
        case 1:
          status = '在售'
          staClass = 'sta-green'
          break
        case 2:
          status = '已锁'
          staClass = 'sta-yellow'
          break
        case 3:
          status = '已售'
          staClass = 'sta-blue'
          canEdit = false
          break
        case 4:
          status = '成交'
          staClass = 'sta-blue'
          canEdit = false
      }
      const editModel = `<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>`
      if (index === 0) {
        let str = `<tr class="table-body-edit"><td class="edit-class-floor" colspan="1">${data.floor}F </td><td colspan="1">${data.householdNo}</td>
              <td colspan="2">${data.hosUnitPrice / 100}元／㎡</td>
              <td class="status-position" colspan="1" data-id="${data.id}"><p class="${staClass}">${status}</p>
              ${canEdit ? editModel : ''}</td>
              </tr>`
        return str
      } else {
        const str = `<tr class="table-body-edit"><td colspan="1">${data.householdNo}</td>
              <td colspan="2">${data.hosUnitPrice / 100}元／㎡</td>
              <td class="status-position" colspan="1" data-id="${data.id}"><p class="${staClass}">${status}</p>
              ${canEdit ? editModel : ''}</td>
              </tr>`
        return str
      }
    },
  //获取楼栋数
  getHowMany:
    (res) => {
      let roofBin = res
      houseType.data.roofBin = roofBin
    },
  //绑定事件
  houseTypeBind:
    () => {
      $('.change-btn .btn-border').on('click', () => {
        location.href = `./type.html?house=${param.content}`
      })
      //房间信息修改事件
      $('#table .status-position span').on('click', e => {
        let str = $(e.target).parent().attr('data-id')
        $.ajax({
          type: "GET",
          url: base + '/admin/house/getHouses.json?id=' + str,
          dataType: "json",
          headers: {
            myToken: Cookies.get('myToken')
          },
        }).then(res => {
          let data = res.object
          let price = () => {
            let price
            data.houseType.hPriceType == 0 ? price = data.houseType.setInArea * (data.houses.hosUnitPrice / 100) : price =
              data.houseType.buildArea * (data.houses.hosUnitPrice / 100)
            return price
          }
          let discountPrice = (fn) => {
            let price
            data.houses.hosRebate == 0 ? price = fn() : price = (data.houses.hosRebate) / 100 * fn()
            return price
          }
          let obj = {
            buildId: data.houses.id,
            buildName: data.houseType.buildName,
            typeName: data.houseType.typeName + ' ' + data.houseType.htStructure,
            hbuNumStr: data.houseBuildingUnit.hbuNumStr,
            floor: data.houses.floor,
            householdNo: data.houses.householdNo,
            htOrientation: data.houseType.htOrientation,
            hPriceType: data.houseType.hPriceType,
            hosUnitPrice: data.houses.hosUnitPrice / 100,
            hosRebate: data.houses.hosRebate,     //1-100 如果返回10代表九折
            hIsSpecial: data.houses.hIsSpecial,
            price: price(),
            discountPrice: Math.floor(discountPrice(price))
          }

          let str = `<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
                     <div class="modal-dialog modal-sm" role="document">
                       <div class="modal-content">
                         <div class="modal-header">
                           <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                           <h4 class="modal-title" id="myModalLabel">修改房源</h4>
                         </div>
                           <div class="modal-body">
                           <p><span class="span-title">楼盘：</span><span>${obj.buildName}</span></p>
                           <p> <span class="span-title">选择户型：</span><span>${obj.typeName}</span></p>
                           <p><span class="span-title">楼栋：</span><span>${obj.hbuNumStr}</span></p>
                           <p><span class="span-title">楼层：</span><span>${obj.floor}</span></p>
                           <p><span class="span-title">门牌号：</span><span>${obj.householdNo}</span></p>
                           <p><span class="span-title">朝向：</span><span>${obj.htOrientation}</span></p>
                           <p><span class="span-title">价格类型:</span><button id="edit-hPriceType" edit-hPriceType="${obj.hPriceType}" class="btn ${obj.hPriceType !== 0 ? 'btn-default' : 'btn-primary'}" type="submit">建面</button>
                             <button class="btn ${obj.hPriceType === 0 ? 'btn-default' : 'btn-primary'}" type="submit">套内</button>
                           </p>
                           <p><span class="span-title" id="hello-hosUnitPrice" hosUnitPrice="${obj.hosUnitPrice}">单价：</span><input id="edit-price" type="text" placeholder="${obj.hosUnitPrice}">元</p>
                           <p><span class="span-title">折扣：</span><input id="edit-discount" type="text" placeholder="${obj.hosRebate}">%</p>
                           <p class="special-price"><span class="span-title">是否特价：</span>
                                <input type="radio" id="price-yes" name="contact" value="是">
                                   <label for="price-yes">是</label>
                                 <input type="radio" id="price-no" name="contact" value="否">
                               <label for="price-no">否</label>
                           </p>
                           <p><span class="span-title">总价：</span><span>${Math.floor(obj.price)}元</span></p>
                           <p><span class="span-title">折扣后总价：</span><span>${Math.floor(obj.discountPrice)}元</span></p>
                           <button id="edit-id" edit-id="${obj.buildId}" type="button" class="btn btn-primary">提交</button>
                          </div>
                       </div>
                      </div>
                     </div>`
          $('#myModal').remove()
          $('.content-wrap').append(str)

          if (obj.hIsSpecial) {
            $('#price-yes').attr('checked', true)
          } else {
            $('#price-no').attr('checked', true)
          }

          $('#myModal').modal('show')
          // //特价非特价按钮功能
          // $('#edit-hIsSpecial').on('click', e => {
          //   let str = $(e.target).attr('edit-hasSpecial')
          //   if (str == 1) {
          //     str = 0
          //   } else if (str == 0) {
          //     str = 1
          //   }
          //   $(e.target).attr('edit-hasSpecial', str)
          //   $(e.target).text(str === 0 ? '否' : '是')
          //   // $(e.target).attr('edit-hasSpecial', str === 0 ? 0 : 1)
          // })

          $('#edit-id').on('click', e => {
            let bargainprice;
            [...document.querySelectorAll('.special-price input')].forEach(k => {
              if (k.checked) {
                // console.log(k.id)
                switch (k.id) {
                  case 'price-yes':
                    bargainprice = 1
                    break
                  case 'price-no':
                    bargainprice = 0
                    break
                }
              }
            })
            let obj = {
              recordId: $(e.target).attr('edit-id'),
              danjia: $('#edit-price')[0].value || $('#hello-hosUnitPrice').attr('hosUnitPrice'),
              zekou: $('#edit-discount')[0].value || 0,
              bargainprice: bargainprice,
              hPriceType: $('#edit-hPriceType').attr('edit-hPriceType')
            }
            console.log('priceasdas', obj.bargainPrice)
            $.ajax({
              type: "POST",
              url: base + '/admin/house/edit.json',
              dataType: "json",
              data: obj,
              headers: {
                myToken: Cookies.get('myToken')
              },
            }).then((res) => {
              //更改成功后刷新页面
              window.location.reload()
              // console.log('asdasdasda', res)
            })
          })
        })
      })

      //绑定查询房间信息事件
      $('#table .status-position p').on('click', e => {
        let str = $(e.target).parent().attr('data-id')
        $.ajax({
          type: "GET",
          url: base + '/admin/house/getHouses.json?id=' + str + '&type=1',
          dataType: "json",
          headers: {
            myToken: Cookies.get('myToken')
          },
        }).then(res => {
          console.log('res:', res)
          let obj = res.object
          let status
          let staClass = ''
          switch (obj.houses.status) {
            case 0:
              status = '待售'
              staClass = 'sta-red'
              break
            case 1:
              status = '在售'
              staClass = 'sta-green'
              break
            case 2:
              status = '已锁'
              staClass = 'sta-yellow'
              break
            case 3:
              status = '已售'
              staClass = 'sta-blue'
              break
            case 4:
              status = '成交'
              staClass = 'sta-blue'
          }

          let orderStr = ``
          if (obj.houseOrder) {
            let payTime = null
            let idNum = []
            let showNum = '';
            let someArr = [4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
            payTime = new Date(obj.houseOrder.payTime)
            idNum = obj.houseOrder.idCardNo;
            [...idNum].forEach((k, index) => {
              // console.log('k:', k, 'index:', index)
              if (someArr.indexOf(index) >= 0) {
                let str = '*'
                showNum += str
              } else {
                let str = k
                showNum += str
              }
            })
            orderStr = ` <p>成交客户:<span>${obj.houseOrder.realName}(${showNum})</span></p>
                           <p>订单号:<span>${obj.houseOrder.identityId}</span></p>
                           <p>定金:<span>${(obj.houseOrder.payAmount / 100).toFixed(2)}元</span></p>
                           <p>成交时间:<span>${payTime ? payTime.toLocaleDateString() : ''} ${payTime ? payTime.toLocaleTimeString() : ''}</span></p>`
          }
          let node = `<div class="modal fade" id="modal-info" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
                     <div class="modal-dialog" role="document">
                       <div class="modal-content">
                         <div class="modal-header">
                           <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                           <h4 class="modal-title" id="myModalLabel">详情</h4>
                         </div>
                           <div class="modal-body">
                           <p>楼盘：<span>${obj.houseType.buildName}</span></p>
                           <p>房号：<span>${obj.houses.householdNo}</span></p>
                           <p>户型描述：<span>${obj.houseType.typeName} ${obj.houseType.htStructure} 建面${obj.houseType.buildArea}㎡</span></p>
                           <p>总价：<span>${obj.houses.hTotalPrice / 100}</span></p>
                           <p>折扣：<span>${obj.houses.hosRebate != 0 ? obj.houses.hosRebate + '%' : '无'}</span></p>
                           <p>折扣后总价：<span>${obj.houses.hosRebate != 0 ? obj.houses.hTotalPrice / 100 * (obj.houses.hosRebate / 100) : obj.houses.hTotalPrice / 100 }</span></p>
                           <p>状态:<span class="${staClass}">${status}</span></p>
                         ${orderStr}
                           </div>
                       </div>
                      </div>
                     </div>`
          $('.content-wrap').find('#modal-info').remove()
          $('.content-wrap').append(node)
          $('#modal-info').modal('show')
        })
      })
    },
  //启动分页组件
  initPageNav: (res) => {
    // console.log(res)
    let data = {
      pageSize: res.pageSize,
      currentPage: res.currentPage,
      pageData: res.pageData
    }
    let fn = new PageNav(data)
    houseType.data.pageNavFn = fn
    // console.log(houseType.data.pageNavFn)
  },
  //配置表身信息
  setTableBodyData: (res) => {
    let arr = []
    res.forEach(k => {
      arr.push(...k.everyFloor)
    })

    let obj = {}
    arr.forEach(k => {
      if (obj['onFloor' + k.floor]) {
        obj['onFloor' + k.floor].push(k)
      } else {
        obj['onFloor' + k.floor] = [k]
      }
    })
    let floorKeys = Object.keys(obj)
    let pageData = []
    floorKeys.forEach(k => {
      pageData.push({[k]: obj[k]})
    })
    houseType.data.pageNavData.pageData = pageData
    //初始化分页组件
    // console.log('data haha:', houseType.data.pageNavData)
    houseType.initPageNav(houseType.data.pageNavData)
    houseType.data.pageNavFn.initPageNav()

    //开始渲染表
    houseType.startRenderTableTitle()
    houseType.startRenderTableBody(houseType.data.pageNavFn.activeData)
  },
  //渲染表头部
  startRenderTableTitle: () => {
    houseType.data.firstHeader.forEach((k, index) => {  //添加表头
      // console.log('header:', k)
      let tableDom = `<table class="table table-container table-bordered" houseTypeId="${k.houseTypeId}"></table>`
      $("#table").append(tableDom)
      //分页逻辑之类处理，如果k楼层大于10则不渲染，取得最大楼层除以10的的整数+1 作为分页li的数量
      $($("#table").children()[index]).append(houseType.renderTableTitle(k, index))
      //渲染每个房间部分
      // houseType.data.everyFloor.forEach((i, index2) => {  //添加房间信息
      //   if (index2 === index) {
      //     i.everyFloor.forEach((x) => {
      //       //渲染表单部分
      //       //x是所有房间，根据index放入储存数组中，渲染的时候
      //       console.log(index2, index)
      //       // houseType.data.storeDataFloors[index].push(x)
      //       $($("#table").children()[index2]).append(houseType.renderTableBody(x, index2))
      //     })
      //   }
      // })

      //如果pageNavFn.activeData中houseTypeId和这个户型相等，在这个户型表头下边添加这个的信息
      let arr = houseType.data.pageNavFn.activeData
      arr.forEach((k, index) => {
        let key = Object.keys(k)
        key.forEach(x => {
          k[x].forEach(y => {
            if (houseType.data.tableBodyObj['floorIndex' + (y.floor - 1)] &&
              houseType.data.tableBodyObj['floorIndex' + (y.floor - 1)].indexOf(y)) {
              houseType.data.tableBodyObj['floorIndex' + (y.floor - 1)].push(y)
            } else {
              houseType.data.tableBodyObj['floorIndex' + (y.floor - 1)] = [y]
            }

          })
        })
      })
    })
  },
  //开始渲染表身
  startRenderTableBody: (res) => {
    // console.log('in start render tableBody')
    // console.log(res)

    if (document.querySelector('#table').children) {

      Array.prototype.forEach.call(document.querySelector('#table').children, (k => {
        res.forEach(resIndex => {
          let keys = Object.keys(resIndex)
          keys.forEach(n => {
            let floorArr = resIndex[n]
            floorArr.forEach((x, index) => {
              // console.log(x)
              if (x.houseTypeId === $(k).attr('houseTypeId')) {
                $(k).append(houseType.renderTableBody(x, index))
              }
            })
          })
        })
      }))
      //添加函数
      // Array.prototype.forEach.call(document.querySelector('#table').children, (k => {
      //   let forArr = Object.keys(houseType.data.tableBodyObj)
      //   forArr.forEach(x => {
      //     let obj = houseType.data.tableBodyObj[x]
      //     obj.forEach((objArr, index) => {
      //       if (objArr.houseTypeId === $(k).attr('houseTypeId')) {
      //         // console.log(objArr, index, $(k))
      //         $(k).append(houseType.renderTableBody(objArr, index))
      //       }
      //     })
      //   })
      // }))
      // console.log(houseType.data.everyFloor)
      // console.log(houseType.data.tableBodyObj)
      houseType.bindPageNavEvent()
      houseType.houseTypeBind()
      houseType.setBootPageNav()
    }
  },
  //绑定分页按钮
  bindPageNavEvent: () => {
    /**增加页码方法**/
    // $('#set-current-page').on('click', e => {
    //   let goPage = $(e.target).siblings()[0].value
    //   houseType.data.pageNavFn.choosePage(new Number(goPage))
    //   //移除之前数据 加载新的数据
    //   console.log('remove')
    //   $('.table-body-edit').remove()
    //   houseType.startRenderTableBody(houseType.data.pageNavFn.activeData)
    // })
    /** pageSize **/
    $('#set-current-page').on('click', e => {
      let pageSize = $(e.target).siblings()[0].value
      houseType.data.pageNavFn.changePageSize(pageSize)
      $('.table-body-edit').remove()
      houseType.startRenderTableBody(houseType.data.pageNavFn.activeData)
      // console.log(houseType.data.pageNavFn)
    })
  },
  //设置分页选择按钮
  setBootPageNav: () => {
    let len = houseType.data.pageNavFn.showData.length - 1
    // console.log('len:', len)
    let nodeList = ''
    for (let i = 0; i <= len; i++) {
      let node = `<li><a href="#" class="nav-page-number" nav-page-number="${i + 1}">${i + 1}</a></li>`
      nodeList += node
    }
    let str = `<nav aria-label="Page navigation">
      <ul class="pagination">
        <li>
          <a href="#" id="page-nav-previous" aria-label="Previous">
            <span aria-hidden="true">&laquo;</span>
          </a>
        </li>
        ${nodeList}
        <li>
          <a href="#" id="page-nav-next" aria-label="Next">
            <span aria-hidden="true">&raquo;</span>
          </a>
        </li>
      </ul>
    </nav>`
    $('#boot-page-nav').children().remove()
    $('#boot-page-nav').append(str)

    //.page-nav-active
    // console.log('hello world')
    // console.log('current page', houseType.data.pageNavFn.currentPage)

    //页数按钮状态
    function navIndexActive() {
      // console.log('select:', document.querySelectorAll('.nav-page-number'))
      Array.prototype.forEach.call(document.querySelectorAll('.nav-page-number'), e => {
        // console.log('attr and page', $(e).attr('nav-page-number'), houseType.data.pageNavFn.currentPage)
        if ($(e).attr('nav-page-number') == houseType.data.pageNavFn.currentPage) {
          // console.log('it is', e)
          $(e).addClass('page-nav-active').siblings().removeClass('page-nav-active')
        }
      })
    }

    navIndexActive()

    //给按钮绑定事件
    $('.nav-page-number').on('click', e => {
      let num = $(e.target).attr('nav-page-number')
      // console.log(num)
      //更改数据
      houseType.data.pageNavFn.choosePage(num)
      //删除之前渲染的数据
      $('.table-body-edit').remove()
      //渲染数据
      houseType.startRenderTableBody(houseType.data.pageNavFn.activeData)
      navIndexActive()
    })

    //上一页按钮绑定事件
    $('#page-nav-previous').on('click', () => {
      let num = houseType.data.pageNavFn.currentPage - 1
      //更改数据
      houseType.data.pageNavFn.choosePage(num)
      //删除之前渲染的数据
      $('.table-body-edit').remove()
      //渲染数据
      houseType.startRenderTableBody(houseType.data.pageNavFn.activeData)
      navIndexActive()
    })

    //下一页按钮绑定事件
    $('#page-nav-next').on('click', () => {
      let num = houseType.data.pageNavFn.currentPage + 1
      //更改数据
      houseType.data.pageNavFn.choosePage(num)
      //删除之前渲染的数据
      $('.table-body-edit').remove()
      //渲染数据
      houseType.startRenderTableBody(houseType.data.pageNavFn.activeData)
      navIndexActive()
    })
  }
}
/*** 获取housetype方法结束 ***/
houseType.init()

/*** 分页组件 ***/
function PageNav(data) {
  // console.log(data)
  this.pageSize = data.pageSize
  this.currentPage = data.currentPage
  this.pageData = data.pageData
  this.showData = []
  this.activeData = []
  //初始化分页组件
  this.initPageNav = () => {
    //按照pageSize currentPage更改数组整理数组
    let pages = Math.floor(this.pageData.length / this.pageSize) + 1
    let arr = this.pageData.slice()
    this.showData = []
    for (let i = 0; i < pages; i++) {
      if (arr.slice(i * this.pageSize, i * this.pageSize + this.pageSize).length > 0) {
        this.showData.push(arr.slice(i * this.pageSize, i * this.pageSize + this.pageSize))
      }
    }
    this.activeData = this.showData[this.currentPage - 1]
    // console.log(this.activeData)
  }
  //显示指定页面
  this.choosePage = (res) => {
    this.currentPage = res
    // console.log('in it:', this.showData)
    if (this.currentPage <= this.showData.length && this.currentPage > 0) {
      this.activeData = this.showData[this.currentPage - 1]
    } else {
      // alert('输入正确页数页数')
    }
  }
  //更改pageSize
  this.changePageSize = (res) => {
    if (res > 0) {
      this.pageSize = Math.floor(res)
      //更改后重新加载
      this.initPageNav()
      // console.log('active data:', this.activeData)
    }
  }
}

// 点击列表的时候传递数据到全局变量
// table.on('click-row.bs.table', (e, data, el) => {
//   storeData = data
// })